﻿using System;
using System.Collections.Generic;
using _5E.Infrastructure.UnitOfWork;
using _5E.NHibernateRepository;
using _5E.NHibernateRepository.Repository;
using NHibernate.Criterion;
using WholesaleOnline.Model;
using WholesaleOnline.Model.Repository;

namespace WholesaleOnline.Repository
{
    public class KeywordRepository : RepositoryBase<WoKeyword, Guid>, IKeywordRepository
    {
        public KeywordRepository(IUnitOfWork uow) : base(uow) { }

        public IList<WoKeyword> FindFor(string keyword, Int32 count)
        {
            return SessionFactory.CurrentSession.QueryOver<WoKeyword>()
                .Where(k => k.Value.IsLike(keyword, MatchMode.Anywhere) ||
                    k.Abbreviation.IsLike(keyword, MatchMode.Anywhere))
                .OrderBy(k => k.Abbreviation).Asc
                .Take(count).List();
        }
    }
}
